///////////////////////////////////////////
// Authors : Mathieu Robitaille - 6396682
//           Sacha Sukhdeo - 6054412
// Class : COMP445
//         Assignment 2
///////////////////////////////////////////
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <winsock.h>
#include <packet.h>
#include <TcpBase.h>
#include <string>
#include <lmcons.h> // see GetUserName(char*, int) on MSDN

#pragma comment (lib, "ws2_32.lib")

class TcpClient : public TcpBase
{
public:
    TcpClient();
    void run(int argc,char * argv[]);	
    ~TcpClient();

private:
    int ConnectToServer(const std::string& servername);
    int OpenSocket(hostent* serverhost);
    void CloseSocket();
    void RequestServer(hostent *serverhost);
    std::string GetServerHostname();
    std::string LogFile() const { return "client.log"; }
	void TcpClient::ThreeWayHandShake();
    bool m_wsaInitialized;
    SOCKET m_serverSocket;                     // Socket descriptor
    SOCKET m_clientSocket;
    SOCKADDR_IN m_servAddr;  // server socket address
    SOCKADDR_IN m_clientAddr;  // server socket address
    bool isHandShaking;
    Req m_req;                      // Request
    Resp *mp_respp;                 // pointer to response
    Msg m_smsg,m_rmsg;                  // receive_message and send_message
    WSADATA wsadata;
    hostent *mp_serverhost;
    char m_username[UNLEN+1];
	int ACK; // the first random value sent to server in 3way-handshake, we expect server to return this...
			 // ...value, else we got problems / lost ACK.
};